"use strict";

const Controller = require("egg").Controller;
const Mock = require("mockjs")
const data = Mock.mock({
    "list|21": [{
        id: "@id",
        housinName: "@ctitle(4,6)",
        address: "@city",
        "price|400-1000": 0,
        dataTime: "@date",
        namer: "@cname",
        "status|1": [0, 1]
    }]
})
class HomeController extends Controller {



    // async housingList() {
    //     const { ctx, app } = this

    //     ctx.body = {
    //         code: 1,
    //         data: data.list,
    //     }
    //     console.log("data", data)
    // }

    async housingList() {
        const { ctx, app } = this

        const data = await app.mysql.select('addtolist')

        ctx.body = {
            code: 1,
            msg: "全部数据",
            data
        }
        console.log("data", data)
    }
















    async allList() {
        const { ctx, app } = this

        const data = await app.mysql.select('list')

        ctx.body = {
            code: 1,
            msg: "全部数据",
            data
        }
    }












    async housingDel() {
        const { ctx, app } = this;
        let { id } = ctx.request.body
        await app.mysql.delete('housing', { id })
        const data = await app.mysql.select('housing')
        ctx.body = {
            code: 1,
            msg: "删除成功",
            data
        }
    }







}

module.exports = HomeController;